<template>
  <div class="photo-footer">
    <div class="photo-footer-left">
      <span class="label">已选择：{{ currentLength }} / {{ maxLength }}</span>
      <el-button type="text" :disabled="!hasChooseList" @click="clearChooseList">清除选择</el-button>
    </div>
    <div class="photo-footer-btns">
      <el-button type="text" @click="onCancel">取 消</el-button>
      <el-button type="primary" :disabled="chooseDisabled" @click.native.prevent="onChoose">确 定</el-button>
    </div>
  </div>
</template>

<script>
import { mapGetters, mapMutations } from 'vuex'

export default {
  name: 'PhotoFooter',
  props: {
    // 基础已选择的数量
    baseLength: { 
      type: Number,
      default: 0
    },
    // 最多可选择数量
    maxLength: {
      type: Number,
      default: 100
    }
  },
  computed: {
    ...mapGetters({
      chooseList: 'photoChooseList'
    }),
    // 是否已经选择
    hasChooseList() {
      return this.chooseList.length > 0 ? true : false
    },
    // 已选择的数量
    currentLength() {
      return this.chooseList.length + this.baseLength
    },
    // 确定是否可用
    chooseDisabled() {
      if (!this.hasChooseList || this.currentLength > this.maxLength) {
        return true
      }
      return false
    },
  },
  methods: {
    onCancel() {
      this.$emit('cancel')
    },
    onChoose() {
      this.onCancel()
      this.$emit('choose', this.chooseList)
    },
    clearChooseList() {
      this.setChooseList([])
    },

    ...mapMutations('photoGroupImage', {
      setChooseList: 'SET_CHOOSE_LIST',
    })
  },
}
</script>

<style lang="scss" scoped>
.photo-footer {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  &-left {
    .label {
      margin-right: 10px;
    }
  }
  &-btns {
    text-align: right;
  }
}
</style>